package ophiux.common.utils;

import java.util.LinkedHashMap;
import java.util.Map;



public class webserviceUtil {
	
	public final static String SOAP_METHOD = "SOAP_METHOD"; 
	public final static String SOAP_NAMESPACE = "SOAP_NAMESPACE";
	public final static String SOAP_PARAMS = "SOAP_PARAMS";
	   
	public static final String HTTP_SOAP_PARAM_TEMPLATE = 
			"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
				  	 SOAP_NAMESPACE+">"+
                     "<soapenv:Body>" +
	                     "<"+SOAP_METHOD+">" +
	                     SOAP_PARAMS         +
	                     "</"+SOAP_METHOD+">"+
                     "</soapenv:Body>" +
             "</soapenv:Envelope>";
	  
	  
	  public static String getHttpSoapParam(String soapMethod,
			  LinkedHashMap<String,Object> soapParamMap,String nameSpace){
		  String soapParams = getSoapParam(soapParamMap);
//		  String HTTP_SOAP_PARAM_TEMPLATE_NEW = HTTP_SOAP_PARAM_TEMPLATE
//				  .replaceAll(SOAP_NAMESPACE, nameSpace)
//				  .replaceAll(SOAP_METHOD, soapMethod)
//				  .replaceAll(SOAP_PARAMS, soapParams);
		  String HTTP_SOAP_PARAM_TEMPLATE_NEW ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
				  nameSpace+">"+
                     "<soapenv:Body>" +
	                     "<"+soapMethod+">" +
	                     soapParams         +
	                     "</"+soapMethod+">"+
                     "</soapenv:Body>" +
             "</soapenv:Envelope>";
		  return HTTP_SOAP_PARAM_TEMPLATE_NEW;
	  }
	  
	  public static String getSoapParam(Map soapParams){
		  String soapParam = "";
		  if(!MapUtil.isEmpty(soapParams)){
			  for(Object key : soapParams.keySet()){
				  String value = (String) soapParams.get(key);
				  soapParam +=  "<"+key+">"+value+"</"+key+">";
			  }
		  }
		  return soapParam;
	  }
	  
}
